package cn.nuc.wwb_1248.proj.daoimpl;

import cn.nuc.wwb_1248.proj.dao.wwbBookDao;
import cn.nuc.wwb_1248.proj.wwbBook;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
@Repository
public class WwbBookDaoImpl implements wwbBookDao {
    private List<wwbBook> books = new ArrayList<wwbBook>();

    public WwbBookDaoImpl(){
        books.add(new wwbBook("1","钢铁是怎样练成的",72,"/img/1.jpg"));
        }
    //通过id,获取对应的书籍
    @Override
    public wwbBook getBook(String id) {
        for (wwbBook book: books) {
            if (book.getwwbId().equals(id)){
                return book;
            }
        }
        return null;
    }
// 插入书籍
    @Override
    public Boolean insertBook(wwbBook wwbBook) {
        boolean flag = false;
        if (books.add(wwbBook)){
            flag = true;
        }
        return flag;
    }
//查找所有书籍
    @Override
    public List<wwbBook> findAllBook() {
        return books;
    }
}
